public class num700 {
    public TreeNode searchBST(TreeNode root, int val) {
       return preorder(root,val);
    }

    private TreeNode preorder(TreeNode root, int val) {
        if(root == null) {
            return null;
        }
       if(root.val == val) {
           return root;
       }
       return val < root.val ? preorder(root.left,val) : preorder(root.right,val);
    }
}
